package team.pwy.mapper;


import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
import team.pwy.pojo.entity.Coupon;

import java.util.List;

@Repository
public interface CouponMapper {

    // 根据用户Id查询优惠券
    @Select("select * from pwy.pwy_coupon where user_id = #{value} order by created_time desc")
    List<Coupon> findByUserId(Integer userId);

    @Delete("delete  from pwy.pwy_coupon where id= #{value}")
    Integer delById(Integer id);

    @Select("select * from pwy.pwy_coupon")
    List<Coupon> findAllCoupon();

    @Select("select * from pwy.pwy_coupon where user_id = #{userId} and status = #{status} order by money desc")
    List<Coupon> findByUserIdStatus(@Param("userId") Integer userId, @Param("status") Integer status);

    @Update("update pwy.pwy_coupon set status = #{status} where id = #{couponId}")
    Integer updateByCouponId(@Param("status") Integer status, @Param("couponId") Integer couponId);

    // 即将过期,和很久才过期
    @Select("select * from pwy.pwy_coupon where updated_by > DATE_ADD(NOW(),INTERVAL  2 HOUR)")
    List<Coupon> findByTimeBefore();

    // 2小时之类
    @Select("select * from pwy.pwy_coupon where updated_by > NOW() and updated_by < DATE_ADD(NOW(),INTERVAL  2 HOUR)")
    List<Coupon> findByTimeAfter();

    Integer add(Coupon coupon);
}
